<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>退货管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../../resources/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../../resources/css/style.css" media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
    <style>

        .hiddenbtn{
            display: none;
        }
    </style>
</head>
<body>
<a class="dayin" type="button" id="dlink"  style="float: right; position: fixed; right: 50px; bottom: 50px; z-index: 999;"></a>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-xs">
            <div class="layui-card">
                <div class="layui-card-header">筛选</div>
                <div class="layui-card-body" pad3="">
                    <div class="layui-form" wid100="">
                        <div class="layui-form-item">
                            <div class="layui-inline layui-col-md12">
                                <label class="layui-form-label">项目名称</label>
                                <div class="layui-input-inline">
                                    <input type="text" class="layui-input"  name="proName" placeholder="请输入项目名称" >
                                </div>
                                <label class="layui-form-label">退货单号</label>
                                <div class="layui-input-inline">
                                    <input type="text" class="layui-input" name="ticket" placeholder="请输入单号" >
                                </div>
                                <label class="layui-form-label">创建日期</label>
                                <div class="layui-input-inline">
                                    <input type="text" class="layui-input" id="test-laydate-start" name="beginTime" placeholder="开始日期" lay-key="1">
                                </div>
                                <div class="layui-form-mid">
                                    -
                                </div>
                                <div class="layui-input-inline">
                                    <input type="text" class="layui-input" id="test-laydate-end" placeholder="结束日期" name="endTime" lay-key="2">
                                </div>
                                <div class="layui-btn-group" >
                                    <button class="layui-btn" data-type="query"><i class="layui-icon">&#xe615;</i>查询</button>
                                </div>
                            </div>

                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-card">
                <table id="ticket" lay-filter="test1"></table>
            </div>
        </div>
    </div>
</div>

<!-- open区域 -->
<div class="layui-fluid" hidden id="returnAlert">
    <form class="layui-form layui-form-pane" action="" id="mm" lay-filter="component-form-group">
        <div class="layui-form-item">
                <label class="layui-form-label">发货单单号</label>
                <div class="layui-input-block">
                    <select name="rmCode" lay-verify="required" lay-filter="rmCode" lay-search="">
                    </select>
                </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-block">
                <textarea name="remark" placeholder="请输入原因，以及需要附带的消息" class="layui-textarea"></textarea>
            </div>
        </div>
        <table id="demo1" lay-filter="test"></table>
        <button type="reset" class="layui-btn layui-btn-primary" hidden name="chongzhi">重置</button>
    </form>
</div>

<!-- tool -->
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
    {{# if(d.comfrim_state === 0 && d.validate_state === -1 ) {}}
        <a class="layui-btn layui-btn-xs layui-bg-green" data-state="0" lay-event="queren">审核</a>
    {{# } else if(d.validate_state === 0) { }}
        <a class="layui-btn layui-btn-xs layui-bg-red" data-state="-1" lay-event="queren">取消审核</a>
    {{# }}}
</script>
<!-- tag -->
<script type="text/html" id="confrimState">
    {{# if (d.comfrim_state=== -1) { }}
        <span class="layui-badge layui-bg-gray">待确认</span>
    {{# } else if(d.comfrim_state=== 0) { }}
        <span class="layui-badge layui-bg-green">已经确认</span>
    {{# } else { }}
        <span class="layui-badge layui-bg-orange">被拒绝</span>
    {{# } }}
</script>
<script type="text/html" id="valiStete">
    {{# if (d.validate_state=== -1) { }}
    <span class="layui-badge layui-bg-gray">待审核</span>
    {{# } else if(d.validate_state=== 0) { }}
    <span class="layui-badge layui-bg-green">审核通过</span>
    {{# } else { }}
    <span class="layui-badge layui-bg-orange">审核不通过</span>
    {{# } }}
</script>
<!-- detail -->
<script type="text/html" id="detail">
    <form class="layui-form-pane">
        <div class="layui-form-item" pane>
            <label class="layui-form-label">退货单单号</label>
            <div class="layui-input-block" >
                <input type="text" class="layui-input" value="{{d.main[0].rt_id}}" disabled/>
            </div>
        </div>
        <div>
            <label class="layui-form-label">确认状态</label>
            <div class="layui-input-block">
                {{# if (d.main[0].comfrim_state=== -1) { }}
                <span class="layui-badge layui-bg-gray">待确认</span>
                {{# } else if(d.main[0].comfrim_state=== 0) { }}
                <span class="layui-badge layui-bg-green">已经确认</span>
                {{# } else { }}
                <span class="layui-badge layui-bg-orange">被拒绝</span>
                {{# } }}
                {{# if (d.main[0].validate_state=== -1) { }}
                <span class="layui-badge layui-bg-gray">待审核</span>
                {{# } else if(d.main[0].validate_state=== 0) { }}
                <span class="layui-badge layui-bg-green">审核通过</span>
                {{# } else { }}
                <span class="layui-badge layui-bg-orange">审核不通过</span>
                {{# } }}
            </div>
        </div>
        <div class="layui-form-item" pane>
            <label class="layui-form-label">创建时间</label>
            <div class="layui-input-block" >
                <input type="text" class="layui-input" value="{{d.main[0].create_time}}" disabled/>
            </div>
        </div>
        <div class="layui-form-item" pane>
            <label class="layui-form-label">备注</label>
            <div class="layui-input-block" >
                <textarea class="layui-textarea"  disabled>{{d.main[0].remarks}}</textarea>
            </div>
        </div>
    </form>
    {{#  if(d.detail.length > 0){ }}
    <table class="layui-table">
        <colgroup>
            <col width="80">
            <col width="130">
        </colgroup>
        <thead>
        <tr>
            <th>ID</th>
            <th>材料名称</th>
            <th>材料规格</th>
            <th>单位</th>
            <th>退货量</th>
        </tr>
        </thead>
        <tbody>
        {{#  layui.each(d.detail, function(index, item){ }}
        <tr>
            <td>{{item.id}}</td>
            <td>{{item.mat_Name}}</td>
            <td>{{item.mat_Spec}}</td>
            <td>{{item.mat_Bit}}</td>
            <td>{{item.rt_num}}</td>
        </tr>
        {{#  }); }}
        </tbody>
    </table>
    {{#  } }}
</script>

<script src="../../../resources/layui/layui.js" charset="utf-8"></script>
<script src="../../../resources/js/style.js"></script>
<script src="../../../resources/js/api.js"></script>
<script src="../../../resources/js/jquery.min.js"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>


    layui.use(['form', 'layedit', 'laydate','table','laytpl','flow'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,table=layui.table
            ,laytpl=layui.laytpl
            ,flow=layui.flow
            ,laydate = layui.laydate;
        //开始日期
        var insStart = laydate.render({
            elem: '#test-laydate-start'
            ,type: 'datetime'
            ,done: function(value, date){
                //更新结束日期的最小日期
//                insEnd.config.min = lay.extend({}, date, {
//                    month: date.month - 1
//                });

                //自动弹出结束日期的选择器
                insEnd.config.elem[0].focus();
            }
        });
        //结束日期
        var insEnd = laydate.render({
            elem: '#test-laydate-end'
            ,min: 0
            ,type: 'datetime'
            ,done: function(value, date){
                //更新开始日期的最大日期
                insStart.config.max = lay.extend({}, date, {
                    month: date.month - 1
                });
            }
        });
        var $ = layui.$, active = {
            query:function () {
                layer.closeAll();
                var proName = $('[name="proName"]').val();
                var ticket = $("input[name='ticket']").val();
                var beginTime = $("input[name='beginTime']").val();
                var endTime = $("input[name='endTime']").val();

                if(!AntiSqlValid(proName) && !AntiSqlValid(ticket)){
                    if(lbq('api/contract/builConProcessList2.do')){
                        API.returnMaterial2({'proName':proName,'beginTime':beginTime,'endTime':endTime,'ticket':ticket,'p':getCookie('yanzheng')})
                    }
                }else {
                    layer.msg('请勿输入特殊符号或敏感文字');
                };
            }
        };
        //为所有按钮绑定事件
        $('.layui-form:first .layui-btn').on('click', function(){
            layer.load(0);
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        //监听工具条
        table.on('tool(test1)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
            var layEvent = obj.event;
            console.log(obj);
            var ss = layer.load(2);
            if(layEvent === 'detail'){ //查看
                //获取模板内容
                ajaxs('/api/return/getReturnTicketDetails2.do','post',{'p': getCookie('yanzheng'),"ticket": obj.data.rt_id},function (data){
                    layer.close(ss);
                    var getTpl=document.getElementById('detail').innerHTML;
                    laytpl(getTpl).render(data.data[0], function(html){
                        layer.open({
                            type: 1 //Page层类型
                            ,area: ['700px', 'auto']
                            ,title: '退货单详情'
                            ,shade: 0.8 //遮罩透明度
                            ,maxmin: true //允许全屏最小化
                            ,anim: 1 //0-6的动画形式，-1不开启
                            ,content: html
                        });
                    });
                });

//                sessionStorage.id=obj.data.cc_UUID;         //缓存id 至详情页调用
//                window.location.href='../../management/contracrAdmin/details.html';
            }  else if(layEvent === 'queren'){ //编辑
                var state = $(this).data("state");
                var rtId = obj.data.rt_id;
                ajaxs('/api/return/updateReturnTicketValiState.do','post',{'p': getCookie('yanzheng'),"rtId": rtId,
                "state":state },function (data){
                    layer.close(ss);
                    layer.msg(data.msg);
                    setTimeout(function () {
                        window.location.reload();
                    },100)
                });


            }
        });

        //拖入打印按钮
        dayintishi('.dayin');
    });


    if(lbq('api/contract/builConProcessList2.do')) {
        API.returnMaterial2({'p': getCookie('yanzheng')});            //获取到的数据传入列表进行渲染
    }


    function isRealNum(val) {
        // isNaN()函数 把空串 空格 以及NUll 按照0来处理 所以先去除
        if (val === "" || val == null) {
            return false;
        }
        return !isNaN(val) ? true : false;
    }
</script>

</body>
</html>